using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Security.Permissions;

using CureConsulting;
using CureConsulting.Common;

namespace Blog.Net.Common.DataObjects
{
	[Serializable]
	public partial class BlogEntry : DataObjectBase
	{
		#region Constructors

		/// <summary>
		/// Create a BlogEntry object Empty Constructor
		/// </summary>
		public BlogEntry() { }

		/// <summary>
		/// Create a BlogEntry object Full Constructor
		/// </summary>
		/// <param name="Subject"></param>
		/// <param name="Subhead"></param>
		/// <param name="Body"></param>
		/// <param name="Views"></param>
		/// <param name="Points"></param>
		/// <param name="Votes"></param>
		/// <param name="CreateDate"></param>
		public BlogEntry( string Subject, string Subhead, string Body, decimal Views, int Points, int Votes, DateTime CreateDate ) : this()
		{
			this.Subject = Subject;
			this.Subhead = Subhead;
			this.Body = Body;
			this.Views = Views;
			this.Points = Points;
			this.Votes = Votes;
			this.CreateDate = CreateDate;
		}
		/// <summary>
		/// Create a BlogEntry object from serialization
		/// </summary>
		protected BlogEntry(SerializationInfo info, StreamingContext context) : base(info, context)
      	{
			_subject = (string)info.GetValue("_subject", typeof(string));
			_subhead = (string)info.GetValue("_subhead", typeof(string));
			_body = (string)info.GetValue("_body", typeof(string));
			_views = (decimal)info.GetValue("_views", typeof(decimal));
			_points = (int)info.GetValue("_points", typeof(int));
			_votes = (int)info.GetValue("_votes", typeof(int));
			_createDate = (DateTime)info.GetValue("_createDate", typeof(DateTime));
			_blogResponses = (IList<BlogResponse>)info.GetValue("_blogResponses", typeof(IList<BlogResponse>));
			_blogCategories = (IList<BlogCategory>)info.GetValue("_blogCategories", typeof(IList<BlogCategory>));
      	}
		#endregion
		
		#region Member Variables
		
		protected string _subject;
		protected string _subhead;
		protected string _body;
		protected decimal _views;
		protected int _points;
		protected int _votes;
		protected DateTime _createDate;
		protected IList<BlogResponse> _blogResponses;
		protected IList<BlogCategory> _blogCategories;

		#endregion

		#region Public Properties
		
		/// <summary>
		/// BlogEntry Subject
		/// </summary>
		public virtual string Subject
		{
			get { return _subject; }
			set
			{
				if (value != null && value.Length > 255)
					throw new ArgumentOutOfRangeException("Invalid value for Subject", value, value.ToString());
				UpdateState(_subject , value);
				_subject = value;
			}
		}

		/// <summary>
		/// BlogEntry Subhead
		/// </summary>
		public virtual string Subhead
		{
			get { return _subhead; }
			set
			{
				if (value != null && value.Length > 255)
					throw new ArgumentOutOfRangeException("Invalid value for Subhead", value, value.ToString());
				UpdateState(_subhead , value);
				_subhead = value;
			}
		}

		/// <summary>
		/// BlogEntry Body
		/// </summary>
		public virtual string Body
		{
			get { return _body; }
			set 
			{
				UpdateState(_body , value);
				_body = value;
			}
		}

		/// <summary>
		/// BlogEntry Views
		/// </summary>
		public virtual decimal Views
		{
			get { return _views; }
			set 
			{
				UpdateState(_views , value);
				_views = value;
			}
		}

		/// <summary>
		/// BlogEntry Points
		/// </summary>
		public virtual int Points
		{
			get { return _points; }
			set 
			{
				UpdateState(_points , value);
				_points = value;
			}
		}

		/// <summary>
		/// BlogEntry Votes
		/// </summary>
		public virtual int Votes
		{
			get { return _votes; }
			set 
			{
				UpdateState(_votes , value);
				_votes = value;
			}
		}

		/// <summary>
		/// BlogEntry CreateDate
		/// </summary>
		public virtual DateTime CreateDate
		{
			get { return _createDate; }
			set 
			{
				UpdateState(_createDate , value);
				_createDate = value;
			}
		}

		/// <summary>
		/// BlogEntry BlogResponses
		/// </summary>
		public virtual IList<BlogResponse> BlogResponses
		{
			get
			{
				if (_blogResponses==null)
				{
					_blogResponses = new SortableBindingList<BlogResponse>();
				}
				return _blogResponses;
			}
			set { _blogResponses = value; }
		}

		/// <summary>
		/// BlogEntry BlogCategories
		/// </summary>
		public virtual IList<BlogCategory> BlogCategories
		{
			get
			{
				if (_blogCategories==null)
				{
					_blogCategories = new SortableBindingList<BlogCategory>();
				}
				return _blogCategories;
			}
			set { _blogCategories = value; }
		}

		
		#endregion
		
		#region Methods
		/// <summary>
        /// Set object data for serialization
        /// </summary>
        /// <param name="info"></param>
        /// <param name="context"></param>
      	[SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
		public override void GetObjectData(SerializationInfo info, StreamingContext context)
      	{
			info.AddValue("_subject", _subject);
			info.AddValue("_subhead", _subhead);
			info.AddValue("_body", _body);
			info.AddValue("_views", _views);
			info.AddValue("_points", _points);
			info.AddValue("_votes", _votes);
			info.AddValue("_createDate", _createDate);
			info.AddValue("_blogResponses", _blogResponses);
			info.AddValue("_blogCategories", _blogCategories);			
         	base.GetObjectData(info, context);
      	}
		#endregion
	}
}